<%@ page import="dao.CollegeDao" %>
<%@ page import="entity.College" %>
<%@ page import="java.util.List" %>
<%@ page import="dao.MajorDao" %>
<%@ page import="entity.Major" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>专业信息修改</title>
</head>
<body>
    <%
        //获取传递过来的待修改数据的id
        String id  = request.getParameter("id");
        //根据id,从数据库中取对应的专业信息（修改前）
        Major major  = new MajorDao().getById(
                             Integer.parseInt(id));
    %>

    <form action="major_edit_save.jsp">
            <input type="hidden" name="id" value="<%=major.getId()%>" />
        <br> 专业名称:<input type="text" name="name"
                            value="<%=major.getName()%>" />
        <br> 所属学院:
            <select name="college_id" >
               <%
                //从学院信息表中读取所有记录，生成<option></option>
                List<College> list  = new CollegeDao().getAll();
                for(College obj:list){
                    //判断某个选项是否是当前专业所在的学院
                    if(obj.getId() == major.getCollege_id() ) {
                        out.println("<option selected value='" + obj.getId() + "' >"
                                + obj.getName()
                                + "</option>");
                    }else{
                        out.println("<option  value='" + obj.getId() + "' >"
                                + obj.getName()
                                + "</option>");
                    }
                }
               %>


            </select>
            <select>
             <option>111</option>
             <option>222</option>
             <option selected>333</option>
             <option>4444</option>
           </select>
        <br> <input type="submit" value="提交" />
    </form>
</body>
</html>
